package org.publish.Controller;

import org.publish.dto.EquationRequest;
import org.publish.dto.EquationResponse;
import org.publish.service.EquationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/equation")
public class EquationController {

    private final EquationService equationService;

    @Autowired
    public EquationController(EquationService equationService) {
        this.equationService = equationService;
    }

    @PostMapping("/solve")
    public EquationResponse solveEquation(@RequestBody EquationRequest request) {
        return equationService.solve(request);
    }

    @GetMapping("/solve")
    public EquationResponse solveEquationByGet(
            @RequestParam double a,
            @RequestParam double b) {
        return equationService.solve(new EquationRequest(a, b));
    }
}
